package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;

public class ProjectStagesDialogFragment extends DialogFragment {
  protected static final String EXTRA_VALUE =
      "com.isunland.managesystem.ui.ProjectStagesDialogFragment.extra_value";
  private int[] choiceIds = new int[] {
      R.string.no_open, R.string.in_open, R.string.hasFinishplan, R.string.already_check,
      R.string.all,
  };
  private String[] choiceStrings = new String[choiceIds.length];
  private String projectState = "";//项目阶段状态
  private String projectStateName = "";//项目阶段名

  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {

    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new OnClickListener() {

          @Override public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              //				//未验收
              //				case 0:
              //
              //					projectState="F";
              //					projectStateName="未验收";
              //					break;
              //					//已验收
              //				case 1:
              //					projectState="T";
              //					projectStateName="已验收";
              //					break;
              //					//全部
              //				case 2:
              //					projectState="";
              //					projectStateName="全部";
              //					break;

              //未开展
              case 0:
                projectState = "WKZ";
                projectStateName = "未开展";
                break;
              //开展中
              case 1:
                projectState = "KZZ";
                projectStateName = "开展中";
                break;
              //已完成
              case 2:
                projectState = "YWC";
                projectStateName = "已完成";
                break;
              //已验收
              case 3:
                projectState = "T";
                projectStateName = "已验收";
                break;
              //全部
              case 4:
                projectState = "";
                projectStateName = "全部";
                break;

              default:
                break;
            }
            CustomerDialog content = new CustomerDialog(projectStateName, projectState);

            Intent i = new Intent();
            i.putExtra(EXTRA_VALUE, content);
            if (getTargetFragment() == null) {
              return;
            }
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);
            dialog.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
